
/*
 * Copyright 2002-2023 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2023原作者。
 *
 *根据Apache许可证2.0版（“许可证”）获得许可；
 *除非符合许可证，否则不得使用此文件。
 *您可以在以下地址获取许可证副本：
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，软件
 *根据许可证分发的内容是按“原样”分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限和
 *许可证下的限制。
 */

package org.springframework.beans.factory.support;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.Supplier;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
 * A root bean definition represents the merged bean definition that backs
 * a specific bean in a Spring BeanFactory at runtime. It might have been created
 * from multiple original bean definitions that inherit from each other,
 * typically registered as {@link GenericBeanDefinition GenericBeanDefinitions}.
 * A root bean definition is essentially the 'unified' bean definition view at runtime.
 *
 * <p>Root bean definitions may also be used for registering individual bean definitions
 * in the configuration phase. However, since Spring 2.5, the preferred way to register
 * bean definitions programmatically is the {@link GenericBeanDefinition} class.
 * GenericBeanDefinition has the advantage that it allows to dynamically define
 * parent dependencies, not 'hard-coding' the role as a root bean definition.
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @author Sam Brannen
 * @see GenericBeanDefinition
 * @see ChildBeanDefinition
 */
/**
 *根bean定义表示支持的合并bean定义
 *运行时Spring BeanFactory中的特定bean。它可能已经创建
 *从彼此继承的多个原始bean定义中，
 *通常注册为｛@link GenericBeanDefinition GenericBeanDefinitions｝。
 *根bean定义本质上是运行时的“统一”bean定义视图。
 *
 *＜p＞根bean定义也可以用于注册单个bean定义
 *在配置阶段。然而，自Spring 2.5以来
 *bean定义以编程方式是｛@link GenericBeanDefinition｝类。
 *GenericBeanDefinition的优点是它允许动态定义
 *父依赖关系，而不是“硬编码”作为根bean定义的角色。
 *
 *@作者Rod Johnson
 *@作者Juergen Hoeller
 *@作者Sam Brannen
 *@参见GenericBeanDefinition
 *@参见ChildBeanDefinition
 */
@SuppressWarnings("serial")
public class RootBeanDefinition extends AbstractBeanDefinition {

	@Nullable
	private BeanDefinitionHolder decoratedDefinition;

	@Nullable
	private AnnotatedElement qualifiedElement;

	/** Determines if the definition needs to be re-merged. */
	volatile boolean stale;

	boolean allowCaching = true;

	boolean isFactoryMethodUnique;

	@Nullable
	volatile ResolvableType targetType;

	/** Package-visible field for caching the determined Class of a given bean definition. */
	@Nullable
	volatile Class<?> resolvedTargetType;

	/** Package-visible field for caching if the bean is a factory bean. */
	@Nullable
	volatile Boolean isFactoryBean;

	/** Package-visible field for caching the return type of a generically typed factory method. */
	@Nullable
	volatile ResolvableType factoryMethodReturnType;

	/** Package-visible field for caching a unique factory method candidate for introspection. */
	@Nullable
	volatile Method factoryMethodToIntrospect;

	/** Package-visible field for caching a resolved destroy method name (also for inferred). */
	@Nullable
	volatile String resolvedDestroyMethodName;

	/** Common lock for the four constructor fields below. */
	final Object constructorArgumentLock = new Object();

	/** Package-visible field for caching the resolved constructor or factory method. */
	@Nullable
	Executable resolvedConstructorOrFactoryMethod;

	/** Package-visible field that marks the constructor arguments as resolved. */
	boolean constructorArgumentsResolved = false;

	/** Package-visible field for caching fully resolved constructor arguments. */
	@Nullable
	Object[] resolvedConstructorArguments;

	/** Package-visible field for caching partly prepared constructor arguments. */
	@Nullable
	Object[] preparedConstructorArguments;

	/** Common lock for the two post-processing fields below. */
	final Object postProcessingLock = new Object();

	/** Package-visible field that indicates MergedBeanDefinitionPostProcessor having been applied. */
	boolean postProcessed = false;

	/** Package-visible field that indicates a before-instantiation post-processor having kicked in. */
	@Nullable
	volatile Boolean beforeInstantiationResolved;

	@Nullable
	private Set<Member> externallyManagedConfigMembers;

	@Nullable
	private Set<String> externallyManagedInitMethods;

	@Nullable
	private Set<String> externallyManagedDestroyMethods;


	/**
	 * Create a new RootBeanDefinition, to be configured through its bean
	 * properties and configuration methods.
	 * @see #setBeanClass
	 * @see #setScope
	 * @see #setConstructorArgumentValues
	 * @see #setPropertyValues
	 */
	/** Determines if the definition needs to be re-merged. */
	易失性布尔过时；

	布尔allowCaching=true；

	布尔isFactoryMethodUnique；

	@可为空
	volatile ResolutibleType targetType；

	/**用于缓存给定bean定义的已确定Class的Package可见字段*/
	@可为空
	挥发性类别<？>已解决目标类型；

	/**如果bean是工厂bean，则用于缓存的包可见字段*/
	@可为空
	易失性布尔isFactoryBean；

	/**用于缓存泛型类型的工厂方法的返回类型的包可见字段*/
	@可为空
	挥发性可分解类型因子MethodReturnType；

	/**用于缓存用于内省的唯一工厂方法候选的包可见字段*/
	@可为空
	挥发性方法因子方法内向；

	/**用于缓存解析的销毁方法名称的包可见字段（也用于推断）*/
	@可为空
	volatile字符串resolvedDestroyMethodName；

	/**下面四个构造函数字段的公共锁*/
	final Object constructorArgumentLock=new Object（）；

	/**用于缓存解析的构造函数或工厂方法的包可见字段*/
	@可为空
	可执行文件resolvedConstructorOrFactoryMethod；

	/**将构造函数参数标记为已解析的包可见字段*/
	boolean constructorArgumentsResolved=false；

	/**用于缓存完全解析的构造函数参数的包可见字段*/
	@可为空
	对象[]resolvedConstructorArguments；

	/**用于缓存部分准备的构造函数参数的包可见字段*/
	@可为空
	对象[]preparedConstructorArguments；

	/**下面两个后处理字段的公共锁*/
	final Object postProcessingLock=新对象（）；

	/**表示已应用MergedBeanDefinitionPostProcessor的包可见字段*/
	boolean postProcessed=false；

	/**包可见字段，指示实例化前的后处理器已启动*/
	@可为空
	volatile Boolean beforeInstanceResolved；

	@可为空
	private Set＜Member＞外部ManagedConfigMembers；

	@可为空
	private Set＜String＞externally ManagedInitMethods；

	@可为空
	private Set＜String＞externally ManagedDestroyMethods；


	/**
	 *创建一个新的RootBeanDefinition，通过其bean进行配置
	 *财产和配置方法。
	 *@参见#setBeanClass
	 *@参见#setScope
	 *@参见#setConstructorArgumentValues
	 *@参见#setPropertyValues
	 */
	public RootBeanDefinition() {
	}

	/**
	 * Create a new RootBeanDefinition for a singleton.
	 * @param beanClass the class of the bean to instantiate
	 * @see #setBeanClass
	 */
	/**
	 *为单例创建新的RootBeanDefinition。
	 *@param beanClass要实例化的bean的类
	 *@参见#setBeanClass
	 */
	public RootBeanDefinition(@Nullable Class<?> beanClass) {
		setBeanClass(beanClass);
	}

	/**
	 * Create a new RootBeanDefinition for a singleton.
	 * @param beanType the type of bean to instantiate
	 * @since 6.0
	 * @see #setTargetType(ResolvableType)
	 */
	/**
	 *为单例创建新的RootBeanDefinition。
	 *@param bean键入要实例化的bean类型
	 *@自6.0起
	 *@参见#setTargetType（可解析类型）
	 */
	public RootBeanDefinition(@Nullable ResolvableType beanType) {
		setTargetType(beanType);
	}

	/**
	 * Create a new RootBeanDefinition for a singleton bean, constructing each instance
	 * through calling the given supplier (possibly a lambda or method reference).
	 * @param beanClass the class of the bean to instantiate
	 * @param instanceSupplier the supplier to construct a bean instance,
	 * as an alternative to a declaratively specified factory method
	 * @since 5.0
	 * @see #setInstanceSupplier
	 */
	/**
	 *为单例bean创建一个新的RootBeanDefinition，构造每个实例
	 *通过调用给定的供应商（可能是lambda或方法引用）。
	 *@param beanClass要实例化的bean的类
	 *@param instanceSupplier构造bean实例的供应商，
	 *作为声明性指定的工厂方法的替代
	 *@自5.0
	 *@参见#setInstanceSupplier
	 */
	public <T> RootBeanDefinition(@Nullable Class<T> beanClass, @Nullable Supplier<T> instanceSupplier) {
		setBeanClass(beanClass);
		setInstanceSupplier(instanceSupplier);
	}

	/**
	 * Create a new RootBeanDefinition for a scoped bean, constructing each instance
	 * through calling the given supplier (possibly a lambda or method reference).
	 * @param beanClass the class of the bean to instantiate
	 * @param scope the name of the corresponding scope
	 * @param instanceSupplier the supplier to construct a bean instance,
	 * as an alternative to a declaratively specified factory method
	 * @since 5.0
	 * @see #setInstanceSupplier
	 */
	/**
	 *为作用域bean创建一个新的RootBeanDefinition，构造每个实例
	 *通过调用给定的供应商（可能是lambda或方法引用）。
	 *@param beanClass要实例化的bean的类
	 *@param scope对应作用域的名称
	 *@param instanceSupplier构造bean实例的供应商，
	 *作为声明性指定的工厂方法的替代
	 *@自5.0
	 *@参见#setInstanceSupplier
	 */
	public <T> RootBeanDefinition(@Nullable Class<T> beanClass, String scope, @Nullable Supplier<T> instanceSupplier) {
		setBeanClass(beanClass);
		setScope(scope);
		setInstanceSupplier(instanceSupplier);
	}

	/**
	 * Create a new RootBeanDefinition for a singleton,
	 * using the given autowire mode.
	 * @param beanClass the class of the bean to instantiate
	 * @param autowireMode by name or type, using the constants in this interface
	 * @param dependencyCheck whether to perform a dependency check for objects
	 * (not applicable to autowiring a constructor, thus ignored there)
	 */
	/**
	 *为单例创建新的RootBeanDefinition，
	 *使用给定的自动连线模式。
	 *@param beanClass要实例化的bean的类
	 *@param autowireMode（按名称或类型），使用此接口中的常量
	 *@param dependencyCheck是否对对象执行依赖性检查
	 *（不适用于自动连接构造函数，因此在那里被忽略）
	 */
	public RootBeanDefinition(@Nullable Class<?> beanClass, int autowireMode, boolean dependencyCheck) {
		setBeanClass(beanClass);
		setAutowireMode(autowireMode);
		if (dependencyCheck && getResolvedAutowireMode() != AUTOWIRE_CONSTRUCTOR) {
			setDependencyCheck(DEPENDENCY_CHECK_OBJECTS);
		}
	}

	/**
	 * Create a new RootBeanDefinition for a singleton,
	 * providing constructor arguments and property values.
	 * @param beanClass the class of the bean to instantiate
	 * @param cargs the constructor argument values to apply
	 * @param pvs the property values to apply
	 */
	/**
	 *为单例创建新的RootBeanDefinition，
	 *提供构造函数参数和属性值。
	 *@param beanClass要实例化的bean的类
	 *@param cargs要应用的构造函数参数值
	 *@param pvs要应用的属性值
	 */
	public RootBeanDefinition(@Nullable Class<?> beanClass, @Nullable ConstructorArgumentValues cargs,
			@Nullable MutablePropertyValues pvs) {

		super(cargs, pvs);
		setBeanClass(beanClass);
	}

	/**
	 * Create a new RootBeanDefinition for a singleton,
	 * providing constructor arguments and property values.
	 * <p>Takes a bean class name to avoid eager loading of the bean class.
	 * @param beanClassName the name of the class to instantiate
	 */
	/**
	 *为单例创建新的RootBeanDefinition，
	 *提供构造函数参数和属性值。
	 *＜p＞采用bean类名以避免急于加载bean类。
	 *@param beanClassName要实例化的类的名称
	 */
	public RootBeanDefinition(String beanClassName) {
		setBeanClassName(beanClassName);
	}

	/**
	 * Create a new RootBeanDefinition for a singleton,
	 * providing constructor arguments and property values.
	 * <p>Takes a bean class name to avoid eager loading of the bean class.
	 * @param beanClassName the name of the class to instantiate
	 * @param cargs the constructor argument values to apply
	 * @param pvs the property values to apply
	 */
	/**
	 *为单例创建新的RootBeanDefinition，
	 *提供构造函数参数和属性值。
	 *＜p＞采用bean类名以避免急于加载bean类。
	 *@param beanClassName要实例化的类的名称
	 *@param cargs要应用的构造函数参数值
	 *@param pvs要应用的属性值
	 */
	public RootBeanDefinition(String beanClassName, ConstructorArgumentValues cargs, MutablePropertyValues pvs) {
		super(cargs, pvs);
		setBeanClassName(beanClassName);
	}

	/**
	 * Create a new RootBeanDefinition as deep copy of the given
	 * bean definition.
	 * @param original the original bean definition to copy from
	 */
	/**
	 *创建一个新的RootBeanDefinition作为给定的
	 *bean定义。
	 *@param original要复制的原始bean定义
	 */
	public RootBeanDefinition(RootBeanDefinition original) {
		super(original);
		this.decoratedDefinition = original.decoratedDefinition;
		this.qualifiedElement = original.qualifiedElement;
		this.allowCaching = original.allowCaching;
		this.isFactoryMethodUnique = original.isFactoryMethodUnique;
		this.targetType = original.targetType;
		this.factoryMethodToIntrospect = original.factoryMethodToIntrospect;
	}

	/**
	 * Create a new RootBeanDefinition as deep copy of the given
	 * bean definition.
	 * @param original the original bean definition to copy from
	 */
	/**
	 *创建一个新的RootBeanDefinition作为给定的
	 *bean定义。
	 *@param original要复制的原始bean定义
	 */
	RootBeanDefinition(BeanDefinition original) {
		super(original);
	}


	@Override
	public String getParentName() {
		return null;
	}

	@Override
	public void setParentName(@Nullable String parentName) {
		if (parentName != null) {
			throw new IllegalArgumentException("Root bean cannot be changed into a child bean with parent reference");
		}
	}

	/**
	 * Register a target definition that is being decorated by this bean definition.
	 */
	/**
	 *注册由这个bean定义修饰的目标定义。
	 */
	public void setDecoratedDefinition(@Nullable BeanDefinitionHolder decoratedDefinition) {
		this.decoratedDefinition = decoratedDefinition;
	}

	/**
	 * Return the target definition that is being decorated by this bean definition, if any.
	 */
	/**
	 *返回此bean定义所修饰的目标定义（如果有的话）。
	 */
	@Nullable
	public BeanDefinitionHolder getDecoratedDefinition() {
		return this.decoratedDefinition;
	}

	/**
	 * Specify the {@link AnnotatedElement} defining qualifiers,
	 * to be used instead of the target class or factory method.
	 * @since 4.3.3
	 * @see #setTargetType(ResolvableType)
	 * @see #getResolvedFactoryMethod()
	 */
	/**
	 *指定｛@link AnnotatedElement｝定义限定符，
	 *以代替目标类或工厂方法。
	 *@自4.3.3
	 *@参见#setTargetType（可解析类型）
	 *@参见#getResolvedFactoryMethod（）
	 */
	public void setQualifiedElement(@Nullable AnnotatedElement qualifiedElement) {
		this.qualifiedElement = qualifiedElement;
	}

	/**
	 * Return the {@link AnnotatedElement} defining qualifiers, if any.
	 * Otherwise, the factory method and target class will be checked.
	 * @since 4.3.3
	 */
	/**
	 *返回｛@link AnnotatedElement｝定义限定符（如果有）。
	 *否则，将检查工厂方法和目标类。
	 *@自4.3.3
	 */
	@Nullable
	public AnnotatedElement getQualifiedElement() {
		return this.qualifiedElement;
	}

	/**
	 * Specify a generics-containing target type of this bean definition, if known in advance.
	 * @since 4.3.3
	 */
	/**
	 *指定包含此bean定义的目标类型的泛型（如果事先已知）。
	 *@自4.3.3
	 */
	public void setTargetType(@Nullable ResolvableType targetType) {
		this.targetType = targetType;
	}

	/**
	 * Specify the target type of this bean definition, if known in advance.
	 * @since 3.2.2
	 */
	/**
	 *指定此bean定义的目标类型（如果事先已知）。
	 *@自3.2.2
	 */
	public void setTargetType(@Nullable Class<?> targetType) {
		this.targetType = (targetType != null ? ResolvableType.forClass(targetType) : null);
	}

	/**
	 * Return the target type of this bean definition, if known
	 * (either specified in advance or resolved on first instantiation).
	 * @since 3.2.2
	 */
	/**
	 *返回此bean定义的目标类型（如果已知）
	 *（预先指定或在第一次实例化时解析）。
	 *@自3.2.2
	 */
	@Nullable
	public Class<?> getTargetType() {
		if (this.resolvedTargetType != null) {
			return this.resolvedTargetType;
		}
		ResolvableType targetType = this.targetType;
		return (targetType != null ? targetType.resolve() : null);
	}

	/**
	 * Return a {@link ResolvableType} for this bean definition,
	 * either from runtime-cached type information or from configuration-time
	 * {@link #setTargetType(ResolvableType)} or {@link #setBeanClass(Class)},
	 * also considering resolved factory method definitions.
	 * @since 5.1
	 * @see #setTargetType(ResolvableType)
	 * @see #setBeanClass(Class)
	 * @see #setResolvedFactoryMethod(Method)
	 */
	/**
	 *返回此bean定义的｛@link ResolutibleType｝，
	 *从运行时缓存的类型信息或从配置时
	 *｛@link#setTargetType（ResolutibleType）｝或｛@link#setBeanClass（Class）｝，
	 *同时考虑已解析的工厂方法定义。
	 *@自5.1
	 *@参见#setTargetType（可解析类型）
	 *@参见#setBeanClass（类）
	 *@参见#setResolvedFactoryMethod（方法）
	 */
	@Override
	public ResolvableType getResolvableType() {
		ResolvableType targetType = this.targetType;
		if (targetType != null) {
			return targetType;
		}
		ResolvableType returnType = this.factoryMethodReturnType;
		if (returnType != null) {
			return returnType;
		}
		Method factoryMethod = this.factoryMethodToIntrospect;
		if (factoryMethod != null) {
			return ResolvableType.forMethodReturnType(factoryMethod);
		}
		return super.getResolvableType();
	}

	/**
	 * Determine preferred constructors to use for default construction, if any.
	 * Constructor arguments will be autowired if necessary.
	 * @return one or more preferred constructors, or {@code null} if none
	 * (in which case the regular no-arg default constructor will be called)
	 * @since 5.1
	 */
	/**
	 *确定用于默认构造的首选构造函数（如果有）。
	 *如果需要，构造函数参数将自动连接。
	 *@返回一个或多个首选构造函数，如果没有，则返回｛@code null｝
	 *（在这种情况下，将调用常规无参数默认构造函数）
	 *@自5.1
	 */
	@Nullable
	public Constructor<?>[] getPreferredConstructors() {
		return null;
	}

	/**
	 * Specify a factory method name that refers to a non-overloaded method.
	 */
	/**
	 *指定引用非重载方法的工厂方法名称。
	 */
	public void setUniqueFactoryMethodName(String name) {
		Assert.hasText(name, "Factory method name must not be empty");
		setFactoryMethodName(name);
		this.isFactoryMethodUnique = true;
	}

	/**
	 * Specify a factory method name that refers to an overloaded method.
	 * @since 5.2
	 */
	/**
	 *指定引用重载方法的工厂方法名称。
	 *@自5.2
	 */
	public void setNonUniqueFactoryMethodName(String name) {
		Assert.hasText(name, "Factory method name must not be empty");
		setFactoryMethodName(name);
		this.isFactoryMethodUnique = false;
	}

	/**
	 * Check whether the given candidate qualifies as a factory method.
	 */
	/**
	 *检查给定的候选人是否符合工厂方法。
	 */
	public boolean isFactoryMethod(Method candidate) {
		return candidate.getName().equals(getFactoryMethodName());
	}

	/**
	 * Set a resolved Java Method for the factory method on this bean definition.
	 * @param method the resolved factory method, or {@code null} to reset it
	 * @since 5.2
	 */
	/**
	 *在此bean定义上为工厂方法设置一个已解析的Java方法。
	 *@param方法解析的工厂方法，或｛@code null｝重置它
	 *@自5.2
	 */
	public void setResolvedFactoryMethod(@Nullable Method method) {
		this.factoryMethodToIntrospect = method;
		if (method != null) {
			setUniqueFactoryMethodName(method.getName());
		}
	}

	/**
	 * Return the resolved factory method as a Java Method object, if available.
	 * @return the factory method, or {@code null} if not found or not resolved yet
	 */
	/**
	 *如果可用，将解析的工厂方法作为Java方法对象返回。
	 *@返回工厂方法，如果未找到或尚未解析，则返回｛@code null｝
	 */
	@Nullable
	public Method getResolvedFactoryMethod() {
		return this.factoryMethodToIntrospect;
	}

	@Override
	public void setInstanceSupplier(@Nullable Supplier<?> supplier) {
		super.setInstanceSupplier(supplier);
		Method factoryMethod = (supplier instanceof InstanceSupplier<?> instanceSupplier ?
				instanceSupplier.getFactoryMethod() : null);
		if (factoryMethod != null) {
			setResolvedFactoryMethod(factoryMethod);
		}
	}

	/**
	 * Mark this bean definition as post-processed,
	 * i.e. processed by {@link MergedBeanDefinitionPostProcessor}.
	 * @since 6.0
	 */
	/**
	 *将此bean定义标记为后处理，
	 *即由{@link MergedBeanDefinitionPostProcessor}处理。
	 *@自6.0起
	 */
	public void markAsPostProcessed() {
		synchronized (this.postProcessingLock) {
			this.postProcessed = true;
		}
	}

	/**
	 * Register an externally managed configuration method or field.
	 */
	/**
	 *注册外部管理的配置方法或字段。
	 */
	public void registerExternallyManagedConfigMember(Member configMember) {
		synchronized (this.postProcessingLock) {
			if (this.externallyManagedConfigMembers == null) {
				this.externallyManagedConfigMembers = new LinkedHashSet<>(1);
			}
			this.externallyManagedConfigMembers.add(configMember);
		}
	}

	/**
	 * Determine if the given method or field is an externally managed configuration member.
	 */
	/**
	 *确定给定的方法或字段是否为外部管理的配置成员。
	 */
	public boolean isExternallyManagedConfigMember(Member configMember) {
		synchronized (this.postProcessingLock) {
			return (this.externallyManagedConfigMembers != null &&
					this.externallyManagedConfigMembers.contains(configMember));
		}
	}

	/**
	 * Get all externally managed configuration methods and fields (as an immutable Set).
	 * @since 5.3.11
	 */
	/**
	 *获取所有外部管理的配置方法和字段（作为不可变的集合）。
	 *@自5.3.11
	 */
	public Set<Member> getExternallyManagedConfigMembers() {
		synchronized (this.postProcessingLock) {
			return (this.externallyManagedConfigMembers != null ?
					Collections.unmodifiableSet(new LinkedHashSet<>(this.externallyManagedConfigMembers)) :
					Collections.emptySet());
		}
	}

	/**
	 * Register an externally managed configuration initialization method &mdash;
	 * for example, a method annotated with JSR-250's
	 * {@link jakarta.annotation.PostConstruct} annotation.
	 * <p>The supplied {@code initMethod} may be the
	 * {@linkplain Method#getName() simple method name} for non-private methods or the
	 * {@linkplain org.springframework.util.ClassUtils#getQualifiedMethodName(Method)
	 * qualified method name} for {@code private} methods. A qualified name is
	 * necessary for {@code private} methods in order to disambiguate between
	 * multiple private methods with the same name within a class hierarchy.
	 */
	/**
	 *注册外部管理的配置初始化方法&mdash；
	 *例如，使用JSR-250注释的方法
	 *｛@link jakarta.annotation.PostConstruct｝注释。
	 *＜p＞提供的｛@code initMethod｝可能是
	 *对于非私有方法或
	 *{@linkplain.springframework.util.ClassUtils#getQualifiedMethodName（方法）
	 *｛@code private｝方法的限定方法名｝。限定名称为
	 *｛@code private｝方法所必需的，以便消除两者之间的歧义
	 *类层次结构中具有相同名称的多个私有方法。
	 */
	public void registerExternallyManagedInitMethod(String initMethod) {
		synchronized (this.postProcessingLock) {
			if (this.externallyManagedInitMethods == null) {
				this.externallyManagedInitMethods = new LinkedHashSet<>(1);
			}
			this.externallyManagedInitMethods.add(initMethod);
		}
	}

	/**
	 * Determine if the given method name indicates an externally managed
	 * initialization method.
	 * <p>See {@link #registerExternallyManagedInitMethod} for details
	 * regarding the format for the supplied {@code initMethod}.
	 */
	/**
	 *确定给定的方法名称是否指示外部管理的
	 *初始化方法。
	 *＜p＞有关详细信息，请参阅｛@link#registerExternalManagedInitMethod｝
	 *关于提供的｛@code initMethod｝的格式。
	 */
	public boolean isExternallyManagedInitMethod(String initMethod) {
		synchronized (this.postProcessingLock) {
			return (this.externallyManagedInitMethods != null &&
					this.externallyManagedInitMethods.contains(initMethod));
		}
	}

	/**
	 * Determine if the given method name indicates an externally managed
	 * initialization method, regardless of method visibility.
	 * <p>In contrast to {@link #isExternallyManagedInitMethod(String)}, this
	 * method also returns {@code true} if there is a {@code private} externally
	 * managed initialization method that has been
	 * {@linkplain #registerExternallyManagedInitMethod(String) registered}
	 * using a qualified method name instead of a simple method name.
	 * @since 5.3.17
	 */
	/**
	 *确定给定的方法名称是否指示外部管理的
	 *初始化方法，而不考虑方法可见性。
	 *＜p＞与｛@link#isExternallyManagedInitMethod（String）｝相反
	 *如果外部存在｛@code private｝，则方法还返回｛@codetrue｝
	 *托管初始化方法
	 *｛@linkplain#registerExternalManagedInitMethod（String）已注册｝
	 *使用限定方法名而不是简单方法名。
	 *@自5.3.17
	 */
	boolean hasAnyExternallyManagedInitMethod(String initMethod) {
		synchronized (this.postProcessingLock) {
			if (isExternallyManagedInitMethod(initMethod)) {
				return true;
			}
			if (this.externallyManagedInitMethods != null) {
				for (String candidate : this.externallyManagedInitMethods) {
					int indexOfDot = candidate.lastIndexOf('.');
					if (indexOfDot >= 0) {
						String methodName = candidate.substring(indexOfDot + 1);
						if (methodName.equals(initMethod)) {
							return true;
						}
					}
				}
			}
			return false;
		}
	}

	/**
	 * Return all externally managed initialization methods (as an immutable Set).
	 * <p>See {@link #registerExternallyManagedInitMethod} for details
	 * regarding the format for the initialization methods in the returned set.
	 * @since 5.3.11
	 */
	/**
	 *返回所有外部管理的初始化方法（作为不可变的Set）。
	 *＜p＞有关详细信息，请参阅｛@link#registerExternalManagedInitMethod｝
	 *关于返回集合中初始化方法的格式。
	 *@自5.3.11
	 */
	public Set<String> getExternallyManagedInitMethods() {
		synchronized (this.postProcessingLock) {
			return (this.externallyManagedInitMethods != null ?
					Collections.unmodifiableSet(new LinkedHashSet<>(this.externallyManagedInitMethods)) :
					Collections.emptySet());
		}
	}

	/**
	 * Resolve the inferred destroy method if necessary.
	 * @since 6.0
	 */
	/**
	 *如有必要，请解析推断的销毁方法。
	 *@自6.0起
	 */
	public void resolveDestroyMethodIfNecessary() {
		setDestroyMethodNames(DisposableBeanAdapter
				.inferDestroyMethodsIfNecessary(getResolvableType().toClass(), this));
	}

	/**
	 * Register an externally managed configuration destruction method &mdash;
	 * for example, a method annotated with JSR-250's
	 * {@link jakarta.annotation.PreDestroy} annotation.
	 * <p>The supplied {@code destroyMethod} may be the
	 * {@linkplain Method#getName() simple method name} for non-private methods or the
	 * {@linkplain org.springframework.util.ClassUtils#getQualifiedMethodName(Method)
	 * qualified method name} for {@code private} methods. A qualified name is
	 * necessary for {@code private} methods in order to disambiguate between
	 * multiple private methods with the same name within a class hierarchy.
	 */
	/**
	 *注册外部管理的配置销毁方法&mdash；
	 *例如，使用JSR-250注释的方法
	 *｛@link jakarta.annotation.PreDestroy｝注释。
	 *＜p＞提供的｛@code destroyMethod｝可能是
	 *对于非私有方法或
	 *{@linkplain.springframework.util.ClassUtils#getQualifiedMethodName（方法）
	 *｛@code private｝方法的限定方法名｝。限定名称为
	 *｛@code private｝方法所必需的，以便消除两者之间的歧义
	 *类层次结构中具有相同名称的多个私有方法。
	 */
	public void registerExternallyManagedDestroyMethod(String destroyMethod) {
		synchronized (this.postProcessingLock) {
			if (this.externallyManagedDestroyMethods == null) {
				this.externallyManagedDestroyMethods = new LinkedHashSet<>(1);
			}
			this.externallyManagedDestroyMethods.add(destroyMethod);
		}
	}

	/**
	 * Determine if the given method name indicates an externally managed
	 * destruction method.
	 * <p>See {@link #registerExternallyManagedDestroyMethod} for details
	 * regarding the format for the supplied {@code destroyMethod}.
	 */
	/**
	 *确定给定的方法名称是否指示外部管理的
	 *破坏方法。
	 *＜p＞有关详细信息，请参阅｛@link#registerExternalManagedDestroyMethod｝
	 *关于提供的｛@code destroyMethod｝的格式。
	 */
	public boolean isExternallyManagedDestroyMethod(String destroyMethod) {
		synchronized (this.postProcessingLock) {
			return (this.externallyManagedDestroyMethods != null &&
					this.externallyManagedDestroyMethods.contains(destroyMethod));
		}
	}

	/**
	 * Determine if the given method name indicates an externally managed
	 * destruction method, regardless of method visibility.
	 * <p>In contrast to {@link #isExternallyManagedDestroyMethod(String)}, this
	 * method also returns {@code true} if there is a {@code private} externally
	 * managed destruction method that has been
	 * {@linkplain #registerExternallyManagedDestroyMethod(String) registered}
	 * using a qualified method name instead of a simple method name.
	 * @since 5.3.17
	 */
	/**
	 *确定给定的方法名称是否指示外部管理的
	 *销毁方法，而不考虑方法可见性。
	 *＜p＞与｛@link#isExternallyManagedDestroyMethod（String）｝相反
	 *如果外部存在｛@code private｝，则方法还返回｛@codetrue｝
	 *管理销毁方法
	 *｛@linkplain#registerExternalManagedDestroyMethod（String）已注册｝
	 *使用限定方法名而不是简单方法名。
	 *@自5.3.17
	 */
	boolean hasAnyExternallyManagedDestroyMethod(String destroyMethod) {
		synchronized (this.postProcessingLock) {
			if (isExternallyManagedDestroyMethod(destroyMethod)) {
				return true;
			}
			if (this.externallyManagedDestroyMethods != null) {
				for (String candidate : this.externallyManagedDestroyMethods) {
					int indexOfDot = candidate.lastIndexOf('.');
					if (indexOfDot >= 0) {
						String methodName = candidate.substring(indexOfDot + 1);
						if (methodName.equals(destroyMethod)) {
							return true;
						}
					}
				}
			}
			return false;
		}
	}

	/**
	 * Get all externally managed destruction methods (as an immutable Set).
	 * <p>See {@link #registerExternallyManagedDestroyMethod} for details
	 * regarding the format for the destruction methods in the returned set.
	 * @since 5.3.11
	 */
	/**
	 *获取所有外部管理的销毁方法（作为不可变集合）。
	 *＜p＞有关详细信息，请参阅｛@link#registerExternalManagedDestroyMethod｝
	 *关于返回集合中销毁方法的格式。
	 *@自5.3.11
	 */
	public Set<String> getExternallyManagedDestroyMethods() {
		synchronized (this.postProcessingLock) {
			return (this.externallyManagedDestroyMethods != null ?
					Collections.unmodifiableSet(new LinkedHashSet<>(this.externallyManagedDestroyMethods)) :
					Collections.emptySet());
		}
	}


	@Override
	public RootBeanDefinition cloneBeanDefinition() {
		return new RootBeanDefinition(this);
	}

	@Override
	public boolean equals(@Nullable Object other) {
		return (this == other || (other instanceof RootBeanDefinition && super.equals(other)));
	}

	@Override
	public String toString() {
		return "Root bean: " + super.toString();
	}

}
